<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Stock extends BaseModel
{
    protected $name = 'stock';

    /**
     * 通过中间表关联用户
     * @return \think\model\relation\BelongsToMany
     */
    public function users(): \think\model\relation\BelongsToMany
    {
        return $this->belongsToMany(SystemUser::class, 'system_stock_user', 'user_id', 'stock_id');
    }

    /**
     * 通过中间表关联设备
     * @return \think\model\relation\BelongsToMany
     */
    public function devices(): \think\model\relation\BelongsToMany
    {
        return $this->belongsToMany(Device::class, 'stock_device', 'device_id', 'stock_id');
    }
}
